.TH std::valarray 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::valarray \- std::valarray

.SH Synopsis
   Defined in header <valarray>
   template< class T >
   class valarray;

   std::valarray is the class for representing and manipulating arrays of values. It
   supports element-wise mathematical operations and various forms of generalized
   subscript operators, slicing and indirect access.

.SH Notes

   std::valarray and helper classes are defined to be free of certain forms of
   aliasing, thus allowing operations on these classes to be optimized similar to the
   effect of the keyword restrict in the C programming language. In addition, functions
   and operators that take valarray arguments are allowed to return proxy objects to
   make it possible for the compiler to optimize an expression such as v1 = a * v2 +
   v3; as a single loop that executes v1[i] = a * v2[i] + v3[i]; avoiding any
   temporaries or multiple passes. However, expression templates make the same
   optimization technique available for any C++ container, and the majority of numeric
   libraries prefer expression templates to valarrays for flexibility. Some C++
   standard library implementations use expression templates to implement efficient
   operations on std::valarray (e.g. GNU libstdc++ and LLVM libc++). Only rarely are
   valarrays optimized any further, as in e.g. Intel Integrated Performance Primitives.

.SH Template parameters

   T - the type of the elements. The type must meet the NumericType requirements

.SH Member types

   Member type Definition
   value_type  T

.SH Member functions

   constructor   constructs new numeric array
                 \fI(public member function)\fP
   destructor    destructs the numeric array
                 \fI(public member function)\fP
   operator=     assigns the contents
                 \fI(public member function)\fP
   operator[]    get/set valarray element, slice, or mask
                 \fI(public member function)\fP
   operator+
   operator-     applies a unary arithmetic operator to each element of the valarray
   operator~     \fI(public member function)\fP
   operator!
   operator+=
   operator-=
   operator*=
   operator/=
   operator%=    applies compound assignment operator to each element of the valarray
   operator&=    \fI(public member function)\fP
   operator|=
   operator^=
   operator<<=
   operator>>=
   swap          swaps with another valarray
                 \fI(public member function)\fP
   size          returns the size of valarray
                 \fI(public member function)\fP
   resize        changes the size of valarray
                 \fI(public member function)\fP
   sum           calculates the sum of all elements
                 \fI(public member function)\fP
   min           returns the smallest element
                 \fI(public member function)\fP
   max           returns the largest element
                 \fI(public member function)\fP
   shift         zero-filling shift the elements of the valarray
                 \fI(public member function)\fP
   cshift        circular shift of the elements of the valarray
                 \fI(public member function)\fP
   apply         applies a function to every element of a valarray
                 \fI(public member function)\fP

.SH Non-member functions

   std::swap(std::valarray)  specializes the std::swap algorithm
   \fI(C++11)\fP                   \fI(function template)\fP
   std::begin(std::valarray) overloads std::begin
   \fI(C++11)\fP                   \fI(function template)\fP
   std::end(std::valarray)   specializes std::end
   \fI(C++11)\fP                   \fI(function template)\fP
   operator+
   operator-
   operator*
   operator/
   operator%                 applies binary operators to each element of two valarrays,
   operator&                 or a valarray and a value
   operator|                 \fI(function template)\fP
   operator^
   operator<<
   operator>>
   operator&&
   operator||
   operator==
   operator!=
   operator<                 compares two valarrays or a valarray with a value
   operator<=                \fI(function template)\fP
   operator>
   operator>=
   abs(std::valarray)        applies the function abs to each element of valarray
                             \fI(function template)\fP
.SH Exponential functions
   exp(std::valarray)        applies the function std::exp to each element of valarray
                             \fI(function template)\fP
   log(std::valarray)        applies the function std::log to each element of valarray
                             \fI(function template)\fP
                             applies the function std::log10 to each element of
   log10(std::valarray)      valarray
                             \fI(function template)\fP
.SH Power functions
                             applies the function std::pow to two valarrays or a
   pow(std::valarray)        valarray and a value
                             \fI(function template)\fP
   sqrt(std::valarray)       applies the function std::sqrt to each element of valarray
                             \fI(function template)\fP
.SH Trigonometric functions
   sin(std::valarray)        applies the function std::sin to each element of valarray
                             \fI(function template)\fP
   cos(std::valarray)        applies the function std::cos to each element of valarray
                             \fI(function template)\fP
   tan(std::valarray)        applies the function std::tan to each element of valarray
                             \fI(function template)\fP
   asin(std::valarray)       applies the function std::asin to each element of valarray
                             \fI(function template)\fP
   acos(std::valarray)       applies the function std::acos to each element of valarray
                             \fI(function template)\fP
   atan(std::valarray)       applies the function std::atan to each element of valarray
                             \fI(function template)\fP
   atan2(std::valarray)      applies the function std::atan2 to a valarray and a value
                             \fI(function template)\fP
.SH Hyperbolic functions
   sinh(std::valarray)       applies the function std::sinh to each element of valarray
                             \fI(function template)\fP
   cosh(std::valarray)       applies the function std::cosh to each element of valarray
                             \fI(function template)\fP
   tanh(std::valarray)       applies the function std::tanh to each element of valarray
                             \fI(function template)\fP

.SH Helper classes

   slice          BLAS-like slice of a valarray: starting index, length, stride
                  \fI(class)\fP
   slice_array    proxy to a subset of a valarray after applying a slice
                  \fI(class template)\fP
                  generalized slice of a valarray: starting index, set of lengths, set
   gslice         of strides
                  \fI(class)\fP
   gslice_array   proxy to a subset of a valarray after applying a gslice
                  \fI(class template)\fP
                  proxy to a subset of a valarray after applying a boolean mask
   mask_array     operator[]
                  \fI(class template)\fP
   indirect_array proxy to a subset of a valarray after applying indirect operator[]
                  \fI(class template)\fP

   Deduction guides\fI(since C++17)\fP

.SH See also

   simd                data-parallel vector type
   (parallelism TS v2) \fI(class template)\fP
   simd_mask           data-parallel type with the element type bool
   (parallelism TS v2) \fI(class template)\fP
